const Koa = require('koa');
const app = new Koa();
const bodyparser = require('koa-bodyparser');
const registerRouter = require('./routers');

// logger
app.use(async (ctx, next) => {
    await next();
    const rt = ctx.response.get("X=Response-Time");
    console.log(`app.js - 10 :${ctx.method} ${ctx.url} - ${rt}`);
});
// parser
app.use(bodyparser());
// x-response-time 
app.use(async (ctx, next) => {
    const start = Date.now();
    await next();
    const ms = Date.now() - start;
    ctx.set("x-response-time", `${ms} ms`);
    ctx.append("append", "ctx.append");
});

// rounters
app.use(registerRouter());

app.listen(3000, () => {
    console.log('server ok');
});
